<?php
	session_start();
	require('include/inc.start.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Find books on getub</title>
<?php include ('common_head.html');?>

<link href="css/terms.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php include ('login.php');?>
<div class="back">	
  <div class="footerBg">
  <div id="frame">
  <?php include ('header.php');?>
  <div class="mainfrm">
  <div class="bluestripfrm_terms">
  <div class="blue_heading_terms">
  <h1>All recently posted books </h1>
  </div>
  </div><!--bluestripfrm-->
<div id="pagecontent_terms">
   <div id="Pagination"></div>
        <br style="clear:both;" />
        <div id="Searchresult">
            This content will be replaced when pagination inits.
        </div>
        
        <!-- Container element for all the Elements that are to be paginated -->
<?php
   include("include/connectionParameters.php");
     $connection = mysql_connect($host,$user,$pass)
		or die ("Can't connect to server, try again later, please");

	mysql_select_db($database);
   
// show all books by default
	$query = "select Books.BookId, Books.Title, Books.Author, Books.ISBN, Books.Edition, BookFormat.Description as BookFormat, Books.Course, Books.Professor, Books.Location, Books.Price, Books.PostDate
from Books, BookFormat
where Books.BookFormat = BookFormat.TypeId order by Books.PostDate desc";
	$result = mysql_query($query,$connection)
		or die ("Problem with reading data from database, try again later.");
		
		while( $row = mysql_fetch_row($result )){
			// get data from database
			$bookId = $row[0];
			$title = $row[1];
			$author = $row[2];
			$isbn = $row[3];
			$edition = $row[4];
			$bookType = $row[5];
			$course = $row[6];
			$professor = $row[7];
			$location = $row[8];
			$price = $row[9];
			$postDate = $row[10];
			
			// extract data in YYYY-MM-DD format
			$dateData = explode("-",$postDate);
			$year = $dateData[0];
			$month = $dateData[1];
			$day = $dateData[2];
			
			if (strlen($location) > 0){
			$location = " - (".$location.")";	
			}
			
			// converting to format "Wednesday, August 05, 2009"
			$labelData = date("l,F d,Y", mktime(0,0,0,$month, $day, $year));
			$bookLink = $title.", ".$author.", ".$edition." - ".$price.$location;
			
			echo " <div id='hiddenresult' style='display:none;'>
                   <div class='result'>
				   <li><a href='bookDetails.php?bookId=$bookId'>".$bookLink."</a> 
				   </li>
				   </div> <!-- result -->
				   </div> <!-- hidden result -->";
			}
			mysql_close($connection);
			
			?>
        </div> <!--page content -->
      <?php include("footer.php"); ?>
     </div><!--mainfrm -->
   </div><!--frame-->
 </div><!--footerBg-->
</div><!--back -->
</body>
</html>
